package com.spark.incoicings.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.spark.incoicings.dao.ProductMapper;
import com.spark.invoicings.entity.Product;
import com.spark.invoicings.utils.Result;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/login")
public class ProductController {
    @Resource
    private ProductMapper productMapper;

    /**
     * 查找所有产品信息
     * @return
     */
    @GetMapping("/selectProductAll")
    public Result selectProductAll(){
        List<Product> products = productMapper.selectList(null);
        return Result.success(200,"success",products);
    }

    /**
     * 根据商品id查找商品
     * @param id
     * @return
     */
    @GetMapping("/selectProduct")
    public Result selectProduct(Integer id){
        Product product = productMapper.selectById(id);
        return Result.success(200,"success",product);
    }
    /**
     * 根据订单明细表的商品id查询商品
     */
    @GetMapping("/selectProductAllById")
    public Result selectProductAllById(Integer id){
        List<Product> products = productMapper.selectList(new QueryWrapper<Product>().eq("product_id", id));
        return Result.success(200,"success",products);
    }
}
